home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / x / volume5 / cxpr / part01 next >
Encoding:
Text File  |  1989-12-05  |  38.9 KB  |  1,337 lines

  1. Path: uunet!island!argv
  2. From: argv@island.uu.net (Dan Heller)
  3. Newsgroups: comp.sources.x
  4. Subject: v05i038: cxpr -- color xpr program, Part01/01
  5. Message-ID: <1237@island.uu.net>
  6. Date: 5 Dec 89 19:44:43 GMT
  7. Organization: Island Graphics, Marin County, California
  8. Lines: 1326
  9. Approved: island!argv@sun.com
  10.  
  11. Submitted-by: uunet!relay.EU.net!sgzh!root (Bruno Pape)
  12. Posting-number: Volume 5, Issue 38
  13. Archive-name: cxpr/part01
  14.  
  15.  
  16.  
  17. [ From the README ]
  18. These are the routines to cxpr.  This version of cxpr is based on the xpr
  19. program provided in the MIT X core distribution.  It uses the output of
  20. xwd to produce a postscript program and image data that when printed
  21. on a color postscript printer generate an image of the window dumped with 
  22. xwd.  This cxpr uses the XY format of xwd as opposed to the Z format used
  23. by the orignal xpr, only outputs for color postscript printers, only
  24. outputs compressed color images, and has only been tested on a Sun 3/60 C/G.
  25.  
  26. #! /bin/sh
  27. # This is a shell archive.  Remove anything before this line, then feed it
  28. # into a shell via "sh file" or similar.  To overwrite existing files,
  29. # type "sh file -c".
  30. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  31. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  32. # If this archive is complete, you will see the following message at the end:
  33. #        "End of shell archive."
  34. # Contents:  cxpr cxpr/Makefile cxpr/README cxpr/cxpr.c cxpr/cxpr.h
  35. #   cxpr/dump_prolog.c cxpr/epilog.h cxpr/escape.c cxpr/fullread.c
  36. #   cxpr/hex.h cxpr/invbits.c cxpr/parse_args.c cxpr/points.c
  37. #   cxpr/print_header.c cxpr/prolog.h cxpr/ps_finish.c
  38. #   cxpr/ps_output.c cxpr/ps_putbuf.c cxpr/ps_setup.c
  39. #   cxpr/read_colormaps.c cxpr/read_header.c cxpr/read_window_name.c
  40. #   cxpr/reverse_byte.h cxpr/setup_layout.c cxpr/swapbits.c
  41. #   cxpr/swaplong.c cxpr/swapshort.c
  42. # Wrapped by argv@island on Tue Dec  5 11:40:44 1989
  43. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  44. if test ! -d 'cxpr' ; then
  45.     echo shar: Creating directory \"'cxpr'\"
  46.     mkdir 'cxpr'
  47. fi
  48. if test -f 'cxpr/Makefile' -a "${1}" != "-c" ; then 
  49.   echo shar: Will not clobber existing file \"'cxpr/Makefile'\"
  50. else
  51. echo shar: Extracting \"'cxpr/Makefile'\" \(1298 characters\)
  52. sed "s/^X//" >'cxpr/Makefile' <<'END_OF_FILE'
  53. X###########################################################################
  54. X# start of Imakefile
  55. X
  56. X OBJS = dump_prolog.o        \
  57. X    escape.o        \
  58. X    fullread.o        \
  59. X    invbits.o        \
  60. X    parse_args.o        \
  61. X    points.o        \
  62. X    print_header.o        \
  63. X    ps_finish.o        \
  64. X    ps_output.o        \
  65. X    ps_putbuf.o        \
  66. X    ps_setup.o        \
  67. X    read_colormaps.o    \
  68. X    read_header.o        \
  69. X    read_window_name.o    \
  70. X    setup_layout.o        \
  71. X    swapbits.o        \
  72. X    swaplong.o        \
  73. X    swapshort.o        \
  74. X    cxpr.o
  75. X
  76. X SRCS = dump_prolog.c        \
  77. X    escape.c        \
  78. X    fullread.c        \
  79. X    invbits.c        \
  80. X    parse_args.c        \
  81. X    points.c        \
  82. X    print_header.c        \
  83. X    ps_finish.c        \
  84. X    ps_output.c        \
  85. X    ps_putbuf.c        \
  86. X    ps_setup.c        \
  87. X    read_colormaps.c    \
  88. X    read_header.c        \
  89. X    read_window_name.c    \
  90. X    setup_layout.c        \
  91. X    swapbits.c        \
  92. X    swaplong.c        \
  93. X    swapshort.c        \
  94. X    cxpr.c
  95. X
  96. X PROGRAM = cxpr
  97. X
  98. Xall:: cxpr
  99. X
  100. Xcxpr:   $(OBJS) $(LOCAL_LIBRARIES)
  101. X    $(RM) $@
  102. X    $(CC) -g -o $@ $(OBJS) $(LOCAL_LIBRARIES) $(LDFLAGS) $(SYSLAST_LIBRARIES)
  103. X
  104. Xrelink::
  105. X    $(RM) $(PROGRAM)
  106. X    $(MAKE) $(MFLAGS) $(PROGRAM)
  107. X
  108. Xdepend:: $(DEPEND)
  109. X
  110. Xdepend::
  111. X    $(DEPEND) -s "# DO NOT DELETE" -- $(CFLAGS) -- $(SRCS)
  112. X
  113. X$(DEPEND):
  114. X    @echo "making $@"; \
  115. X    cd $(DEPENDSRC); $(MAKE)
  116. X
  117. Xclean::
  118. X    $(RM) $(PROGRAM)
  119. X
  120. X###########################################################################
  121. X# Imake.tmpl common rules for all Makefiles - do not edit
  122. X
  123. Xemptyrule::
  124. X
  125. Xclean::
  126. X    $(RM_CMD) \#*
  127. X
  128. XMakefile:: $(IMAKE)
  129. X
  130. END_OF_FILE
  131. if test 1298 -ne `wc -c <'cxpr/Makefile'`; then
  132.     echo shar: \"'cxpr/Makefile'\" unpacked with wrong size!
  133. fi
  134. # end of 'cxpr/Makefile'
  135. fi
  136. if test -f 'cxpr/README' -a "${1}" != "-c" ; then 
  137.   echo shar: Will not clobber existing file \"'cxpr/README'\"
  138. else
  139. echo shar: Extracting \"'cxpr/README'\" \(3654 characters\)
  140. sed "s/^X//" >'cxpr/README' <<'END_OF_FILE'
  141. X/*
  142. X *    Author:      G. Bruno Pape, Computer Consultant, B.S. Computer Engineering
  143. X *
  144. X *    Address:  P.O. Box 368, Thomaston, Connecticut, 06787, USA.
  145. X *    
  146. X *    Copyright (c) G. Bruno Pape 1989.
  147. X *    All rights reserved.
  148. X *
  149. X *    Permission is granted to anyone to use this software for any purpose on
  150. X *    any computer system, and to alter it and redistribute it freely, subject
  151. X *    to the following restrictions:
  152. X *    
  153. X *    1. The author is not responsible for the consequences of use or
  154. X *    redistribution of this software, no matter how awful.
  155. X *    
  156. X *    2. The origin of this software must not be misrepresented, either by
  157. X *    explicit claim or by omission.
  158. X *    
  159. X *    3. Altered versions must be plainly marked as such, and must not be
  160. X *    misrepresented as being the original software. 
  161. X *    
  162. X *    4. This notice may not be removed or altered.
  163. X *    
  164. X *
  165. X *    First distribution, November 30, 1989.
  166. X *
  167. X *    This software was developed while on holiday in Switzerland which
  168. X *    is why some things are in centimeters, pages are A4.
  169. X *
  170. X *    I also do systems programming and administration in BSD and System V
  171. X *    UNIX environments, network and network application development,
  172. X *    X-Windows application development, 3D graphic and graphic animation
  173. X *    program development, computational fluid dynamics, expert systems,
  174. X *    and almost anything else you might want done with a computer.
  175. X *    My favorite computer is a MAC, but I only do development work on Suns,
  176. X *    Silicon Graphics, DECs, Crays, and of course IBM mainframes. 
  177. X */
  178. X
  179. XCXPR:
  180. X
  181. XThese are the routines to cxpr.  This version of cxpr is based on the xpr
  182. Xprogram provided in the MIT X core distribution.  It uses the output of
  183. Xxwd to produce a postscript program and image data that when printed
  184. Xon a color postscript printer generate an image of the window dumped with 
  185. Xxwd.  This cxpr uses the XY format of xwd as opposed to the Z format used
  186. Xby the orignal xpr, only outputs for color postscript printers, only
  187. Xoutputs compressed color images, and has only been tested on a Sun 3/60 C/G.
  188. X
  189. Xcxpr:
  190. Xtotal 38
  191. X-rw-r--r--  1 bruno    users        1287 Jul  7 14:30 Makefile
  192. X-rw-r--r--  1 bruno    users         106 Jul  7 13:50 dump_prolog.c
  193. X-rw-r--r--  1 bruno    users          60 Jul  7 13:50 epilog.h
  194. X-rw-r--r--  1 bruno    users         380 Jul  7 13:50 escape.c
  195. X-rw-r--r--  1 bruno    users         508 Jul  7 13:50 fullread.c
  196. X-rw-r--r--  1 bruno    users         649 Jul  7 13:50 hex.h
  197. X-rw-r--r--  1 bruno    users         115 Jul  7 13:50 invbits.c
  198. X-rw-r--r--  1 bruno    users        3611 Jul  7 14:05 parse_args.c
  199. X-rw-r--r--  1 bruno    users         114 Jul  7 13:50 points.c
  200. X-rw-r--r--  1 bruno    users        2142 Jul  7 14:09 print_header.c
  201. X-rw-r--r--  1 bruno    users        1936 Jul  7 15:36 prolog.h
  202. X-rw-r--r--  1 bruno    users          94 Jul  7 13:50 ps_finish.c
  203. X-rw-r--r--  1 bruno    users        1303 Jul  7 15:21 ps_output.c
  204. X-rw-r--r--  1 bruno    users        1253 Jul  7 13:50 ps_putbuf.c
  205. X-rw-r--r--  1 bruno    users        3345 Jul  7 13:50 ps_setup.c
  206. X-rw-r--r--  1 bruno    users         509 Jul  7 14:25 read_colormaps.c
  207. X-rw-r--r--  1 bruno    users         604 Jul  7 13:50 read_header.c
  208. X-rw-r--r--  1 bruno    users         251 Jul  7 13:51 read_window_name.c
  209. X-rw-r--r--  1 bruno    users        1600 Jul  7 13:51 reverse_byte.h
  210. X-rw-r--r--  1 bruno    users         918 Jul  7 13:51 setup_layout.c
  211. X-rw-r--r--  1 bruno    users         196 Jul  7 13:51 swapbits.c
  212. X-rw-r--r--  1 bruno    users         279 Jul  7 13:51 swaplong.c
  213. X-rw-r--r--  1 bruno    users         200 Jul  7 13:51 swapshort.c
  214. X-rw-r--r--  1 bruno    users         291 Jul  7 13:51 xpr.c
  215. X-rw-r--r--  1 bruno    users        1003 Jul  7 14:04 xpr.h
  216. X
  217. END_OF_FILE
  218. if test 3654 -ne `wc -c <'cxpr/README'`; then
  219.     echo shar: \"'cxpr/README'\" unpacked with wrong size!
  220. fi
  221. # end of 'cxpr/README'
  222. fi
  223. if test -f 'cxpr/cxpr.c' -a "${1}" != "-c" ; then 
  224.   echo shar: Will not clobber existing file \"'cxpr/cxpr.c'\"
  225. else
  226. echo shar: Extracting \"'cxpr/cxpr.c'\" \(292 characters\)
  227. sed "s/^X//" >'cxpr/cxpr.c' <<'END_OF_FILE'
  228. X#include "cxpr.h"
  229. X#include "hex.h"
  230. X
  231. Xmain(argc, argv)
  232. Xchar **argv;
  233. X{
  234. X    parse_args (argc, argv);
  235. X
  236. X    if ( read_header() ) exit(1);
  237. X
  238. X    read_window_name();
  239. X
  240. X    if ( win.ncolors ) read_colormaps();
  241. X
  242. X    setup_layout();
  243. X
  244. X    if ( flags & F_DEBUG ) print_header();
  245. X
  246. X    ps_setup();
  247. X
  248. X    ps_output();
  249. X
  250. X    ps_finish();
  251. X}
  252. END_OF_FILE
  253. if test 292 -ne `wc -c <'cxpr/cxpr.c'`; then
  254.     echo shar: \"'cxpr/cxpr.c'\" unpacked with wrong size!
  255. fi
  256. # end of 'cxpr/cxpr.c'
  257. fi
  258. if test -f 'cxpr/cxpr.h' -a "${1}" != "-c" ; then 
  259.   echo shar: Will not clobber existing file \"'cxpr/cxpr.h'\"
  260. else
  261. echo shar: Extracting \"'cxpr/cxpr.h'\" \(1003 characters\)
  262. sed "s/^X//" >'cxpr/cxpr.h' <<'END_OF_FILE'
  263. X#include <X11/Xlib.h>
  264. X#include <sys/uio.h>
  265. X#include <stdio.h>
  266. X#include <fcntl.h>
  267. X#include <pwd.h>
  268. X#include <X11/XWDFile.h>
  269. X
  270. X#define W_MAX 2400
  271. X#define H_MAX 3150
  272. X
  273. X#define US_PAPER_WIDTH    2550        /* 8.5 inches * 300 DPI */
  274. X#define US_PAPER_LENGTH    3300        /* 11 inches  * 300 DPI */
  275. X
  276. X#define PAPER_WIDTH    2430        /* 21.0 cm / 2.54 cm/inch * 300 DPI */
  277. X#define PAPER_LENGTH    3480        /* 29.5 cm / 2.54 cm/inch * 300 DPI */
  278. X
  279. X#define COMMENTVERSION "PS-Adobe-1.0"
  280. X
  281. X#define min(x,y) (((x)<(y))?(x):(y))
  282. X
  283. X#define F_PORTRAIT      1
  284. X#define F_LANDSCAPE      2
  285. X#define F_DEBUG          4
  286. X#define F_APPEND     16
  287. X#define F_NOFF         32
  288. X#define F_COMPACT    128
  289. X#define F_INVERT    256
  290. X
  291. X#define LINELEN 72      /* number of CHARS (bytes*2) per line of bitmap output*/
  292. X
  293. XXWDFileHeader    win;
  294. XXColor        *colors;
  295. X
  296. Xchar        *infilename    = "stdin",
  297. X        *header        = NULL,
  298. X        *trailer    = NULL,
  299. X        *window_name,
  300. X        *escape();
  301. X
  302. Xint        top_margin,
  303. X        left_margin,
  304. X        scale    =  0,
  305. X        split    =  1,
  306. X        top    = -1,
  307. X        left    = -1,
  308. X        width    = -1,
  309. X        height    = -1,
  310. X        flags    = F_PORTRAIT,
  311. X        points();
  312. END_OF_FILE
  313. if test 1003 -ne `wc -c <'cxpr/cxpr.h'`; then
  314.     echo shar: \"'cxpr/cxpr.h'\" unpacked with wrong size!
  315. fi
  316. # end of 'cxpr/cxpr.h'
  317. fi
  318. if test -f 'cxpr/dump_prolog.c' -a "${1}" != "-c" ; then 
  319.   echo shar: Will not clobber existing file \"'cxpr/dump_prolog.c'\"
  320. else
  321. echo shar: Extracting \"'cxpr/dump_prolog.c'\" \(106 characters\)
  322. sed "s/^X//" >'cxpr/dump_prolog.c' <<'END_OF_FILE'
  323. X#include "prolog.h"
  324. X
  325. Xdump_prolog(flags) {
  326. X    char **p = ps_prolog;
  327. X    while (*p) printf("%s\n",*p++);
  328. X}
  329. END_OF_FILE
  330. if test 106 -ne `wc -c <'cxpr/dump_prolog.c'`; then
  331.     echo shar: \"'cxpr/dump_prolog.c'\" unpacked with wrong size!
  332. fi
  333. # end of 'cxpr/dump_prolog.c'
  334. fi
  335. if test -f 'cxpr/epilog.h' -a "${1}" != "-c" ; then 
  336.   echo shar: Will not clobber existing file \"'cxpr/epilog.h'\"
  337. else
  338. echo shar: Extracting \"'cxpr/epilog.h'\" \(60 characters\)
  339. sed "s/^X//" >'cxpr/epilog.h' <<'END_OF_FILE'
  340. Xchar *ps_epilog[] = {
  341. X    "",
  342. X    "showpage",
  343. X    "%%Trailer",
  344. X    0
  345. X};
  346. END_OF_FILE
  347. if test 60 -ne `wc -c <'cxpr/epilog.h'`; then
  348.     echo shar: \"'cxpr/epilog.h'\" unpacked with wrong size!
  349. fi
  350. # end of 'cxpr/epilog.h'
  351. fi
  352. if test -f 'cxpr/escape.c' -a "${1}" != "-c" ; then 
  353.   echo shar: Will not clobber existing file \"'cxpr/escape.c'\"
  354. else
  355. echo shar: Extracting \"'cxpr/escape.c'\" \(380 characters\)
  356. sed "s/^X//" >'cxpr/escape.c' <<'END_OF_FILE'
  357. X/*
  358. X *    make a version of s in which control characters are deleted and
  359. X *    special characters are escaped.
  360. X */
  361. X
  362. Xchar *escape(s)
  363. Xchar *s;
  364. X{
  365. X    static char buf[200];
  366. X    char *p = buf;
  367. X
  368. X    for (;*s;s++) {
  369. X    if (*s < ' ' || *s > 0176) continue;
  370. X    if (*s==')' || *s=='(' || *s == '\\') {
  371. X        sprintf(p,"\\%03o",*s);
  372. X        p += 4;
  373. X    }
  374. X    else *p++ = *s;
  375. X    }
  376. X    *p = 0;
  377. X    return buf;
  378. X}
  379. END_OF_FILE
  380. if test 380 -ne `wc -c <'cxpr/escape.c'`; then
  381.     echo shar: \"'cxpr/escape.c'\" unpacked with wrong size!
  382. fi
  383. # end of 'cxpr/escape.c'
  384. fi
  385. if test -f 'cxpr/fullread.c' -a "${1}" != "-c" ; then 
  386.   echo shar: Will not clobber existing file \"'cxpr/fullread.c'\"
  387. else
  388. echo shar: Extracting \"'cxpr/fullread.c'\" \(508 characters\)
  389. sed "s/^X//" >'cxpr/fullread.c' <<'END_OF_FILE'
  390. X#include <stdio.h>
  391. X
  392. X/*
  393. X *    fullread() is the same as read(), except that it guarantees to 
  394. X *    read all the bytes requested.
  395. X */
  396. X
  397. Xfullread (file, data, nbytes)
  398. Xint file;
  399. Xchar *data;
  400. Xint nbytes;
  401. X{
  402. X    int bytes_read;
  403. X    while ((bytes_read = read(file, data, nbytes)) != nbytes) {
  404. X        if (bytes_read < 0) {
  405. X            perror ("error while reading standard input");
  406. X            return;
  407. X        } else if (bytes_read == 0) {
  408. X            fprintf (stderr, "xpr: premature end of file\n");
  409. X            return;
  410. X        }
  411. X        nbytes -= bytes_read;
  412. X        data += bytes_read;
  413. X    }
  414. X}
  415. END_OF_FILE
  416. if test 508 -ne `wc -c <'cxpr/fullread.c'`; then
  417.     echo shar: \"'cxpr/fullread.c'\" unpacked with wrong size!
  418. fi
  419. # end of 'cxpr/fullread.c'
  420. fi
  421. if test -f 'cxpr/hex.h' -a "${1}" != "-c" ; then 
  422.   echo shar: Will not clobber existing file \"'cxpr/hex.h'\"
  423. else
  424. echo shar: Extracting \"'cxpr/hex.h'\" \(649 characters\)
  425. sed "s/^X//" >'cxpr/hex.h' <<'END_OF_FILE'
  426. X/*
  427. X * mapping tables to map a byte in to the hex representation of its
  428. X * bit-reversal
  429. X */
  430. X
  431. Xchar hex1[]="084c2a6e195d3b7f084c2a6e195d3b7f084c2a6e195d3b7f084c2a6e195d3b7f\
  432. X084c2a6e195d3b7f084c2a6e195d3b7f084c2a6e195d3b7f084c2a6e195d3b7f\
  433. X084c2a6e195d3b7f084c2a6e195d3b7f084c2a6e195d3b7f084c2a6e195d3b7f\
  434. X084c2a6e195d3b7f084c2a6e195d3b7f084c2a6e195d3b7f084c2a6e195d3b7f";
  435. X
  436. Xchar hex2[]="000000000000000088888888888888884444444444444444cccccccccccccccc\
  437. X2222222222222222aaaaaaaaaaaaaaaa6666666666666666eeeeeeeeeeeeeeee\
  438. X111111111111111199999999999999995555555555555555dddddddddddddddd\
  439. X3333333333333333bbbbbbbbbbbbbbbb7777777777777777ffffffffffffffff";
  440. END_OF_FILE
  441. if test 649 -ne `wc -c <'cxpr/hex.h'`; then
  442.     echo shar: \"'cxpr/hex.h'\" unpacked with wrong size!
  443. fi
  444. # end of 'cxpr/hex.h'
  445. fi
  446. if test -f 'cxpr/invbits.c' -a "${1}" != "-c" ; then 
  447.   echo shar: Will not clobber existing file \"'cxpr/invbits.c'\"
  448. else
  449. echo shar: Extracting \"'cxpr/invbits.c'\" \(115 characters\)
  450. sed "s/^X//" >'cxpr/invbits.c' <<'END_OF_FILE'
  451. X_invbits (b, n)
  452. Xregister unsigned char *b;
  453. Xregister long n;
  454. X{
  455. X    do {
  456. X        *b = ~*b;
  457. X        b++;
  458. X        } while (--n > 0);
  459. X    
  460. X}
  461. END_OF_FILE
  462. if test 115 -ne `wc -c <'cxpr/invbits.c'`; then
  463.     echo shar: \"'cxpr/invbits.c'\" unpacked with wrong size!
  464. fi
  465. # end of 'cxpr/invbits.c'
  466. fi
  467. if test -f 'cxpr/parse_args.c' -a "${1}" != "-c" ; then 
  468.   echo shar: Will not clobber existing file \"'cxpr/parse_args.c'\"
  469. else
  470. echo shar: Extracting \"'cxpr/parse_args.c'\" \(3611 characters\)
  471. sed "s/^X//" >'cxpr/parse_args.c' <<'END_OF_FILE'
  472. X#include <stdio.h>
  473. X#include <fcntl.h>
  474. X#include <X11/XWDFile.h>
  475. X
  476. X#define F_PORTRAIT      1
  477. X#define F_DEBUG          4
  478. X#define F_APPEND     16
  479. X#define F_NOFF         32
  480. X#define F_COMPACT    128
  481. X#define F_INVERT    256
  482. X
  483. Xextern    XWDFileHeader    win;
  484. Xextern    char        *infilename, *header, *trailer, *window_name;
  485. Xextern    int        top_margin, left_margin, scale, split,
  486. X            top, left, width, height, flags;
  487. X
  488. Xparse_args(argc, argv)
  489. X
  490. Xregister    int    argc;
  491. Xregister    char    **argv;
  492. X
  493. X{
  494. X
  495. X    char    *output_filename    = NULL;
  496. X    register    int    f, len, pos;
  497. X    double    atof();
  498. X    int        atoi();
  499. X
  500. X    argc--;
  501. X    argv++;
  502. X
  503. X    while ( argc > 0 && argv[0][0] == '-' ) {
  504. X    len = strlen(*argv);
  505. X    switch (argv[0][1]) {
  506. X    case 'a':        /* -append <filename> */
  507. X        if (!bcmp(*argv, "-append", len)) {
  508. X        argc--; argv++;
  509. X        output_filename = *argv;
  510. X        flags |= F_APPEND;
  511. X        }
  512. X        break;
  513. X
  514. X    case 'd':
  515. X        if (!bcmp(*argv, "-debug", len)) flags |= F_DEBUG;
  516. X        break;
  517. X
  518. X    case 'h':        /* -height <inches> */
  519. X        if (len <= 3) {
  520. X        fprintf(stderr, "xpr: ambiguous option: \"%s\"\n", *argv);
  521. X        exit(1);
  522. X        }
  523. X        if (!bcmp(*argv, "-height", len)) {
  524. X        argc--; argv++;
  525. X        height = (int)(300.0 * atof(*argv));
  526. X        } else if (!bcmp(*argv, "-header", len)) {
  527. X        argc--; argv++;
  528. X        header = *argv;
  529. X        }
  530. X        break;
  531. X
  532. X    case 'l':        /* -landscape | -left <inches> */
  533. X        if (!bcmp(*argv, "-landscape", len)) {
  534. X        flags &= ~F_PORTRAIT;
  535. X        } else if (!bcmp(*argv, "-left", len)) {
  536. X        argc--; argv++;
  537. X        left = (int)(300.0 * atof(*argv));
  538. X        }
  539. X        break;
  540. X
  541. X    case 'n':        /*  -noff */
  542. X        if (!bcmp(*argv, "-noff", len)) {
  543. X        flags |= F_NOFF;
  544. X        }
  545. X        break;
  546. X
  547. X    case 'o':        /* -output <filename> */
  548. X        if (!bcmp(*argv, "-output", len)) {
  549. X        argc--; argv++;
  550. X        output_filename = *argv;
  551. X        }
  552. X        break;
  553. X
  554. X    case 'p':        /* -portrait */
  555. X        if (!bcmp(*argv, "-portrait", len)) {
  556. X        flags |= F_PORTRAIT;
  557. X        }
  558. X        break;
  559. X
  560. X    case 'c':        /* -compact */
  561. X        if (!bcmp(*argv, "-compact", len)) {
  562. X        flags |= F_COMPACT;
  563. X        }
  564. X        break;
  565. X
  566. X    case 'r':        /* -rv */
  567. X        if (!bcmp(*argv, "-rv", len)) {
  568. X        flags |= F_INVERT;
  569. X        }
  570. X        break;
  571. X
  572. X    case 's':        /* -scale <scale> | -split <n-pages> */
  573. X        if (!bcmp(*argv, "-scale", len)) {
  574. X        argc--; argv++;
  575. X        scale = atoi(*argv);
  576. X        } else if (!bcmp(*argv, "-split", len)) {
  577. X        argc--; argv++;
  578. X        split = atoi(*argv);
  579. X        }
  580. X        break;
  581. X
  582. X    case 't':        /* -top <inches> */
  583. X        if (len <= 2) {
  584. X        fprintf(stderr, "xpr: ambigous option: \"%s\"\n", *argv);
  585. X        exit(1);
  586. X        }
  587. X        if (!bcmp(*argv, "-top", len)) {
  588. X        argc--; argv++;
  589. X        top = (int)(300.0 * atof(*argv));
  590. X        } else if (!bcmp(*argv, "-trailer", len)) {
  591. X        argc--; argv++;
  592. X        trailer = *argv;
  593. X        }
  594. X        break;
  595. X
  596. X    case 'w':        /* -width <inches> */
  597. X        if (!bcmp(*argv, "-width", len)) {
  598. X        argc--; argv++;
  599. X        width = (int)(300.0 * atof(*argv));
  600. X        }
  601. X        break;
  602. X
  603. X    }
  604. X    argc--; argv++;
  605. X    }
  606. X
  607. X    if (argc > 0) {
  608. X    f = open(*argv, O_RDONLY, 0);
  609. X    if (f < 0) {
  610. X        fprintf(stderr, "xpr: error opening \"%s\" for input\n", *argv);
  611. X        perror("");
  612. X        exit(1);
  613. X    }
  614. X    dup2(f, 0);
  615. X    close(f);
  616. X    infilename = *argv;
  617. X    }
  618. X
  619. X    if (output_filename != NULL) {
  620. X    if (!(flags & F_APPEND)) {
  621. X        f = open(output_filename, O_CREAT|O_WRONLY|O_TRUNC, 0664);
  622. X    } else {
  623. X        f = open(output_filename, O_WRONLY, 0);
  624. X    }
  625. X    if (f < 0) {
  626. X        fprintf(stderr, "xpr: error opening \"%s\" for output\n", 
  627. X            output_filename);
  628. X        perror("xpr");
  629. X        exit(1);
  630. X    }
  631. X    if (flags & F_APPEND) {
  632. X        pos = lseek(f, 0, 2);          /* get eof position */
  633. X        if (flags & F_NOFF) pos -= 3; /* set position before trailing */
  634. X                       /*     formfeed and reset */
  635. X        lseek(f, pos, 0);              /* set pointer */
  636. X    }
  637. X    dup2(f, 1);
  638. X    close(f);
  639. X    }
  640. X}
  641. END_OF_FILE
  642. if test 3611 -ne `wc -c <'cxpr/parse_args.c'`; then
  643.     echo shar: \"'cxpr/parse_args.c'\" unpacked with wrong size!
  644. fi
  645. # end of 'cxpr/parse_args.c'
  646. fi
  647. if test -f 'cxpr/points.c' -a "${1}" != "-c" ; then 
  648.   echo shar: Will not clobber existing file \"'cxpr/points.c'\"
  649. else
  650. echo shar: Extracting \"'cxpr/points.c'\" \(114 characters\)
  651. sed "s/^X//" >'cxpr/points.c' <<'END_OF_FILE'
  652. Xint points(n)
  653. X{
  654. X    /* scale n from pixels (1/300 inch) to points (1/72 inch) */
  655. X    n *= 72;
  656. X    return n/300;
  657. X}
  658. END_OF_FILE
  659. if test 114 -ne `wc -c <'cxpr/points.c'`; then
  660.     echo shar: \"'cxpr/points.c'\" unpacked with wrong size!
  661. fi
  662. # end of 'cxpr/points.c'
  663. fi
  664. if test -f 'cxpr/print_header.c' -a "${1}" != "-c" ; then 
  665.   echo shar: Will not clobber existing file \"'cxpr/print_header.c'\"
  666. else
  667. echo shar: Extracting \"'cxpr/print_header.c'\" \(2142 characters\)
  668. sed "s/^X//" >'cxpr/print_header.c' <<'END_OF_FILE'
  669. X#include <stdio.h>
  670. X#include <X11/Xlib.h>
  671. X#include <X11/XWDFile.h>
  672. X
  673. X#define F_PORTRAIT      1
  674. X
  675. Xextern    XWDFileHeader    win;
  676. Xextern    XColor        *colors;
  677. Xextern    int        flags, scale;
  678. X
  679. Xprint_header()
  680. X{
  681. X    register    i;
  682. X    fprintf(stderr, "header size    = %d\n", win.header_size);     
  683. X    fprintf(stderr, "file version    = %d\n", win.file_version);    
  684. X    fprintf(stderr, "pixmap format    = %s\n",
  685. X        (win.pixmap_format==XYPixmap) ? "XYPixmap" : "ZPixmap" );
  686. X    fprintf(stderr, "pixmap depth    = %d\n", win.pixmap_depth);
  687. X    fprintf(stderr, "pixmap width    = %d\n", win.pixmap_width);
  688. X    fprintf(stderr, "pixmap height    = %d\n", win.pixmap_height);
  689. X    fprintf(stderr, "xoffset         = %d\n", win.xoffset);     
  690. X    fprintf(stderr, "byte order      = %d\n", win.byte_order); 
  691. X    fprintf(stderr, "bitmap unit    = %d\n", win.bitmap_unit);
  692. X    fprintf(stderr, "bitmap order    = %d\n", win.bitmap_bit_order);  
  693. X    fprintf(stderr, "bitmap pad      = %d\n", win.bitmap_pad);    
  694. X    fprintf(stderr, "bits per pixel    = %d\n", win.bits_per_pixel);
  695. X    fprintf(stderr, "bytes per line    = %d\n", win.bytes_per_line);    
  696. X    fprintf(stderr, "visual class    = %d\n", win.visual_class);
  697. X    fprintf(stderr, "red mask       = %d\n", win.red_mask);      
  698. X    fprintf(stderr, "green mask      = %d\n", win.green_mask);
  699. X    fprintf(stderr, "blue mask      = %d\n", win.blue_mask);    
  700. X    fprintf(stderr, "bits per rgb    = %d\n", win.bits_per_rgb);
  701. X    fprintf(stderr, "colormap entrs    = %d\n", win.colormap_entries); 
  702. X    fprintf(stderr, "ncolors         = %d\n", win.ncolors);    
  703. X    fprintf(stderr, "window width    = %d\n", win.window_width);    
  704. X    fprintf(stderr, "window height    = %d\n", win.window_height);
  705. X    fprintf(stderr, "window x        = %d\n", win.window_x);    
  706. X    fprintf(stderr, "window y       = %d\n", win.window_y);
  707. X    fprintf(stderr, "window brd wid    = %d\n", win.window_bdrwidth);
  708. X    fprintf(stderr, "Orientation: %s, Scale: %d\n", 
  709. X        ( flags & F_PORTRAIT ) ? "Portrait" : "Landscape", scale);
  710. X        for ( i = 0; i < 6; i++ ) {
  711. X        fprintf(stderr, "colors[%d].pixel = %d\n", i, colors[i].pixel );
  712. X        fprintf(stderr, "colors[%d].red   = %d\n", i, colors[i].red );
  713. X        fprintf(stderr, "colors[%d].green = %d\n", i, colors[i].green );
  714. X        fprintf(stderr, "colors[%d].blue  = %d\n", i, colors[i].blue );
  715. X    }
  716. X}
  717. END_OF_FILE
  718. if test 2142 -ne `wc -c <'cxpr/print_header.c'`; then
  719.     echo shar: \"'cxpr/print_header.c'\" unpacked with wrong size!
  720. fi
  721. # end of 'cxpr/print_header.c'
  722. fi
  723. if test -f 'cxpr/prolog.h' -a "${1}" != "-c" ; then 
  724.   echo shar: Will not clobber existing file \"'cxpr/prolog.h'\"
  725. else
  726. echo shar: Extracting \"'cxpr/prolog.h'\" \(1936 characters\)
  727. sed "s/^X//" >'cxpr/prolog.h' <<'END_OF_FILE'
  728. X/*
  729. X *    postscript "program" to unpack and print the bitmaps being sent
  730. X */
  731. X
  732. Xchar *ps_prolog[] = {
  733. X
  734. X"%%Pages: 1",
  735. X"%%EndProlog",
  736. X"%%Page: 1 1",
  737. X"",
  738. X"/bitgen",
  739. X"    {",
  740. X"        /out_buff exch def",
  741. X"        {",
  742. X"            in_buff_index    in_buff_len    eq {",
  743. X"                currentfile in_buff readhexstring pop pop",
  744. X"                /in_buff_index 0 def",
  745. X"            } if",
  746. X"",
  747. X"            /leng    in_buff    in_buff_index    get def",
  748. X"            /in_buff_index    in_buff_index 1    add def",
  749. X"            /byte    in_buff    in_buff_index    get def",
  750. X"            /in_buff_index    in_buff_index 1    add def",
  751. X"            /bytes    leng    out_buff_index    add def",
  752. X"",
  753. X"            bytes width lt {",
  754. X"                out_buff_index 1 bytes 1 sub",
  755. X"                { out_buff exch byte put } for",
  756. X"                /out_buff_index out_buff_index leng add def",
  757. X"            } if",
  758. X"            bytes width eq {",
  759. X"                out_buff_index 1 width 1 sub",
  760. X"                { out_buff exch byte put } for",
  761. X"                /out_buff_index 0 def",
  762. X"                out_buff",
  763. X"                exit",
  764. X"            } if",
  765. X"            bytes width gt {",
  766. X"                out_buff_index 1 width 1 sub",
  767. X"                { out_buff exch byte put } for",
  768. X"                /in_buff_index in_buff_index 1 sub def",
  769. X"                /in_buff_index in_buff_index 1 sub def",
  770. X"                in_buff in_buff_index",
  771. X"                out_buff_index leng add width sub put",
  772. X"                /out_buff_index 0 def",
  773. X"                out_buff",
  774. X"                exit",
  775. X"            } if",
  776. X"        } loop",
  777. X"    } def",
  778. X"",
  779. X"",
  780. X"/bitdump    % stack: width, height, scale",
  781. X"        % dump a bit image with lower left corner at origin",
  782. X"    {",
  783. X"        % read arguments",
  784. X"        /iscale exch def",
  785. X"        /height exch def",
  786. X"        /width exch def",
  787. X"",
  788. X"        /in_buff_len    40            def",
  789. X"        /in_buff    in_buff_len    string    def",
  790. X"        /in_buff_index    in_buff_len        def",
  791. X"        /red_buff    width        string    def",
  792. X"        /grn_buff    width        string    def",
  793. X"        /blu_buff    width        string    def",
  794. X"        /out_buff_index    0            def",
  795. X"",
  796. X"        % scale appropriately",
  797. X"        width iscale mul height iscale mul scale",
  798. X"",
  799. X"        % read and dump the image",
  800. X"        width height 8 [width 0 0 height neg 0 height]",
  801. X"            { red_buff bitgen }",
  802. X"            { grn_buff bitgen }",
  803. X"            { blu_buff bitgen } true 3 colorimage",
  804. X"    } def",
  805. X"gsave",
  806. X0
  807. X};
  808. END_OF_FILE
  809. if test 1936 -ne `wc -c <'cxpr/prolog.h'`; then
  810.     echo shar: \"'cxpr/prolog.h'\" unpacked with wrong size!
  811. fi
  812. # end of 'cxpr/prolog.h'
  813. fi
  814. if test -f 'cxpr/ps_finish.c' -a "${1}" != "-c" ; then 
  815.   echo shar: Will not clobber existing file \"'cxpr/ps_finish.c'\"
  816. else
  817. echo shar: Extracting \"'cxpr/ps_finish.c'\" \(94 characters\)
  818. sed "s/^X//" >'cxpr/ps_finish.c' <<'END_OF_FILE'
  819. X#include "epilog.h"
  820. X
  821. Xps_finish()
  822. X{
  823. X    char **p = ps_epilog;
  824. X
  825. X    while (*p) printf("%s\n",*p++);
  826. X}
  827. END_OF_FILE
  828. if test 94 -ne `wc -c <'cxpr/ps_finish.c'`; then
  829.     echo shar: \"'cxpr/ps_finish.c'\" unpacked with wrong size!
  830. fi
  831. # end of 'cxpr/ps_finish.c'
  832. fi
  833. if test -f 'cxpr/ps_output.c' -a "${1}" != "-c" ; then 
  834.   echo shar: Will not clobber existing file \"'cxpr/ps_output.c'\"
  835. else
  836. echo shar: Extracting \"'cxpr/ps_output.c'\" \(1303 characters\)
  837. sed "s/^X//" >'cxpr/ps_output.c' <<'END_OF_FILE'
  838. X#include <stdio.h>
  839. X#include <X11/Xlib.h>
  840. X#include <X11/XWDFile.h>
  841. X
  842. X#define F_PORTRAIT      1
  843. X#define F_DEBUG          4
  844. X#define F_COMPACT    128
  845. X#define F_INVERT    256
  846. X
  847. Xextern    XWDFileHeader    win;
  848. X
  849. Xextern    XColor        *colors;
  850. X
  851. Xps_output()
  852. X{
  853. X    int            iw = win.pixmap_width, ih = win.pixmap_height; 
  854. X    int            iwb = win.bytes_per_line;
  855. X    char            *buffer, *color_buffer;
  856. X    unsigned    long    swaptest = 1;
  857. X    register    int    i, j, k, l;
  858. X    static        char    hex[]    = "0123456789abcdef";
  859. X    extern        char    hex1[], hex2[];
  860. X
  861. X    if ( (buffer=(char *)malloc((unsigned)( ih*iw+iwb-iw ))) == NULL ) {
  862. X        fprintf(stderr,"xpr: cannot allocate %d bytes\n",ih*iw+iwb-iw);
  863. X        exit(1);
  864. X    }
  865. X    if ( (color_buffer=(char *)malloc((unsigned)( ih*iw*3 ))) == NULL ) {
  866. X        fprintf(stderr,"xpr: cannot allocate %d bytes\n",ih*iw*3);
  867. X        exit(1);
  868. X    }
  869. X
  870. X    for ( i = 0; i < ih; i++ ) fullread( 0, (char *) &buffer[i*iw], iwb );
  871. X
  872. X    for ( i = 0, k = 0; i < ih; i++ ) {
  873. X        for ( j = i * iw; j < i * iw + iw; j++ ) 
  874. X            color_buffer[k++] = colors[buffer[j]].red / 257;
  875. X        for ( j = i * iw; j < i * iw + iw; j++ ) 
  876. X            color_buffer[k++] = colors[buffer[j]].green / 257;
  877. X        for ( j = i * iw; j < i * iw + iw; j++ ) 
  878. X            color_buffer[k++] = colors[buffer[j]].blue / 257;
  879. X    }
  880. X
  881. X    if (win.bitmap_bit_order == MSBFirst)
  882. X        _swapbits( color_buffer, (long) ih * iw * 3 );
  883. X
  884. X    ps_putbuf( color_buffer, ih * iw * 3 );
  885. X}
  886. END_OF_FILE
  887. if test 1303 -ne `wc -c <'cxpr/ps_output.c'`; then
  888.     echo shar: \"'cxpr/ps_output.c'\" unpacked with wrong size!
  889. fi
  890. # end of 'cxpr/ps_output.c'
  891. fi
  892. if test -f 'cxpr/ps_putbuf.c' -a "${1}" != "-c" ; then 
  893.   echo shar: Will not clobber existing file \"'cxpr/ps_putbuf.c'\"
  894. else
  895. echo shar: Extracting \"'cxpr/ps_putbuf.c'\" \(1253 characters\)
  896. sed "s/^X//" >'cxpr/ps_putbuf.c' <<'END_OF_FILE'
  897. X/*
  898. X *    Dump some bytes in hex, with bits in each byte reversed.
  899. X */
  900. X
  901. Xint ps_putbuf( buffer, bytes )
  902. Xregister unsigned    char    *buffer;
  903. Xregister        int    bytes;
  904. X{
  905. X    register        int    run_length = 0, count = 0;
  906. X    register unsigned    char    current_byte = *buffer;
  907. X    static            char    hex[] = "0123456789abcdef";
  908. X    extern            char    hex1[], hex2[];
  909. X
  910. X    while ( bytes-- ) {
  911. X        if ( *buffer != current_byte || ++run_length == 255 ) {
  912. X            if ( ++count > 20 ) {
  913. X                printf("\n");
  914. X                count = 1;
  915. X            }
  916. X            putchar ( hex[ run_length >>  4 ] );
  917. X            putchar ( hex[ run_length & 0xf ] );
  918. X/*            printf  ( " < run_length = %d\t", run_length );    */
  919. X            putchar ( hex1[ current_byte ] );
  920. X            putchar ( hex2[ current_byte ] );
  921. X/*            printf  ( " < current_byte %d\n", current_byte );    */
  922. X            if ( run_length == 255 ) {
  923. X                run_length = 0;
  924. X                current_byte = *( buffer + 1 );
  925. X            } else {
  926. X                run_length = 1;
  927. X                current_byte = *buffer;
  928. X            }
  929. X        }
  930. X        buffer++;
  931. X    }
  932. X    if ( run_length > 0 ) {
  933. X        if ( ++count > 20 ) {
  934. X            printf("\n");
  935. X            count = 1;
  936. X        }
  937. X        putchar ( hex[ run_length >>  4 ] );
  938. X        putchar ( hex[ run_length & 0xf ] );
  939. X        putchar ( hex1[ current_byte ] );
  940. X        putchar ( hex2[ current_byte ] );
  941. X    }
  942. X    while ( count != 20 ) {
  943. X        count++;
  944. X        putchar ( '0' );
  945. X        putchar ( '0' );
  946. X        putchar ( '0' );
  947. X        putchar ( '0' );
  948. X    }
  949. X}
  950. END_OF_FILE
  951. if test 1253 -ne `wc -c <'cxpr/ps_putbuf.c'`; then
  952.     echo shar: \"'cxpr/ps_putbuf.c'\" unpacked with wrong size!
  953. fi
  954. # end of 'cxpr/ps_putbuf.c'
  955. fi
  956. if test -f 'cxpr/ps_setup.c' -a "${1}" != "-c" ; then 
  957.   echo shar: Will not clobber existing file \"'cxpr/ps_setup.c'\"
  958. else
  959. echo shar: Extracting \"'cxpr/ps_setup.c'\" \(3345 characters\)
  960. sed "s/^X//" >'cxpr/ps_setup.c' <<'END_OF_FILE'
  961. X#include <pwd.h>
  962. X#include <X11/XWDFile.h>
  963. X
  964. X#define PAPER_WIDTH    2430        /* 21.0 cm / 2.54 cm/inch * 300 DPI */
  965. X#define PAPER_LENGTH    3480        /* 29.5 cm / 2.54 cm/inch * 300 DPI */
  966. X
  967. X#define COMMENTVERSION "PS-Adobe-1.0"
  968. X
  969. X#define F_PORTRAIT      1
  970. X#define F_DEBUG          4
  971. X#define F_APPEND     16
  972. X#define F_NOFF         32
  973. X#define F_COMPACT    128
  974. X#define F_INVERT    256
  975. X
  976. Xextern    XWDFileHeader    win;
  977. Xextern    char        *infilename, *header, *trailer, *window_name;
  978. Xextern    int        scale, top, left, width, height, flags;
  979. Xextern    char        *escape();
  980. X
  981. Xps_setup()
  982. X{
  983. X    char    hostname[256];
  984. X    struct    passwd    *pswd;
  985. X    long    clock;
  986. X    int        lm, bm; /* left and bottom margins in portrait orientation */
  987. X    int        iw = win.pixmap_width, ih = win.pixmap_height; 
  988. X
  989. X    pswd = getpwuid (getuid ());
  990. X    (void) gethostname (hostname, sizeof(hostname) );
  991. X
  992. X    printf ("%%!%s\n", COMMENTVERSION);
  993. X    printf ("%%%%Creator: %s:%s (%s)\n",hostname,pswd->pw_name,pswd->pw_gecos);
  994. X    printf ("%%%%Title: %s (%s)\n", infilename, window_name );
  995. X    printf ("%%%%CreationDate: %s", (time (&clock), ctime (&clock)));
  996. X    printf ("%%%%EndComments\n");
  997. X
  998. X    dump_prolog(flags);
  999. X
  1000. X    if ( flags & F_PORTRAIT ) {
  1001. X    lm = (left > 0)? left : ((PAPER_WIDTH - scale * iw) / 2);
  1002. X    bm = (top > 0)? (PAPER_LENGTH - top - scale * ih)
  1003. X        : ((PAPER_LENGTH - scale * ih) / 2);
  1004. X    if (header || trailer) {
  1005. X        printf("gsave\n");
  1006. X        printf("/Times-Roman findfont 15 scalefont setfont\n");
  1007. X        /* origin at bottom left corner of image */
  1008. X        printf("%d %d translate\n",points(lm),points(bm));
  1009. X        if (header) {
  1010. X        char *label = escape(header);
  1011. X        printf("%d (%s) stringwidth pop sub 2 div %d moveto\n",
  1012. X            points(iw*scale), label, points(ih*scale) + 10);
  1013. X        printf("(%s) show\n",label);
  1014. X        }
  1015. X        if (trailer) {
  1016. X        char *label = escape(trailer);
  1017. X        printf("%d (%s) stringwidth pop sub 2 div -20 moveto\n",
  1018. X            points(iw*scale), label);
  1019. X        printf("(%s) show\n",label);
  1020. X        }
  1021. X        printf("grestore\n");
  1022. X    }
  1023. X    /* set resolution to device units (300/inch) */
  1024. X    printf("72 300 div dup scale\n");
  1025. X    /* move to lower left corner of image */
  1026. X    printf("%d %d translate\n",lm,bm);
  1027. X    /* dump the bitmap */
  1028. X    printf("%d %d %d bitdump\n",iw,ih,scale);
  1029. X    } else { /* orientation == LANDSCAPE */
  1030. X    /* calculate margins */
  1031. X    lm = (top > 0)? (PAPER_WIDTH - top - scale * ih)
  1032. X        : ((PAPER_WIDTH - scale * ih) / 2);
  1033. X    bm = (left > 0)? (PAPER_LENGTH - left - scale * iw)
  1034. X        : ((PAPER_LENGTH - scale * iw) / 2);
  1035. X
  1036. X    if (header || trailer) {
  1037. X        printf("gsave\n");
  1038. X        printf("/Times-Roman findfont 15 scalefont setfont\n");
  1039. X        /* origin at top left corner of image */
  1040. X        printf("%d %d translate\n",points(lm),points(bm + scale * iw));
  1041. X        /* rotate to print the titles */
  1042. X        printf("-90 rotate\n");
  1043. X        if (header) {
  1044. X        char *label = escape(header);
  1045. X        printf("%d (%s) stringwidth pop sub 2 div %d moveto\n",
  1046. X            points(iw*scale), label, points(ih*scale) + 10);
  1047. X        printf("(%s) show\n",label);
  1048. X        }
  1049. X        if (trailer) {
  1050. X        char *label = escape(trailer);
  1051. X        printf("%d (%s) stringwidth pop sub 2 div -20 moveto\n",
  1052. X            points(iw*scale), label);
  1053. X        printf("(%s) show\n",label);
  1054. X        }
  1055. X        printf("grestore\n");
  1056. X    }
  1057. X    /* set resolution to device units (300/inch) */
  1058. X    printf("72 300 div dup scale\n");
  1059. X    /* move to lower left corner of image */
  1060. X    printf("%d %d translate\n",lm,bm);
  1061. X    /* dump the bitmap */
  1062. X    printf("%d %d %d bitdump\n",ih,iw,scale);
  1063. X    }
  1064. X}
  1065. END_OF_FILE
  1066. if test 3345 -ne `wc -c <'cxpr/ps_setup.c'`; then
  1067.     echo shar: \"'cxpr/ps_setup.c'\" unpacked with wrong size!
  1068. fi
  1069. # end of 'cxpr/ps_setup.c'
  1070. fi
  1071. if test -f 'cxpr/read_colormaps.c' -a "${1}" != "-c" ; then 
  1072.   echo shar: Will not clobber existing file \"'cxpr/read_colormaps.c'\"
  1073. else
  1074. echo shar: Extracting \"'cxpr/read_colormaps.c'\" \(509 characters\)
  1075. sed "s/^X//" >'cxpr/read_colormaps.c' <<'END_OF_FILE'
  1076. X#include <X11/Xlib.h>
  1077. X#include <X11/XWDFile.h>
  1078. X
  1079. Xextern        XWDFileHeader    win;
  1080. Xextern        XColor        *colors;
  1081. X
  1082. Xread_colormaps()
  1083. X{
  1084. X    register    i;
  1085. X    unsigned long    swaptest = 1;
  1086. X
  1087. X    colors = (XColor*)malloc((unsigned)(win.ncolors*sizeof(XColor)));
  1088. X
  1089. X    fullread(0, (char *)colors, (int) (win.ncolors * sizeof(XColor)));
  1090. X
  1091. X    if (*(char *) &swaptest) {
  1092. X        for (i = 0; i < win.ncolors; i++) {
  1093. X        _swaplong((char *) &colors[i].pixel, (long) sizeof(long));
  1094. X        _swapshort((char *) &colors[i].red, (long) (3 * sizeof(short)));
  1095. X        }
  1096. X    }
  1097. X}
  1098. END_OF_FILE
  1099. if test 509 -ne `wc -c <'cxpr/read_colormaps.c'`; then
  1100.     echo shar: \"'cxpr/read_colormaps.c'\" unpacked with wrong size!
  1101. fi
  1102. # end of 'cxpr/read_colormaps.c'
  1103. fi
  1104. if test -f 'cxpr/read_header.c' -a "${1}" != "-c" ; then 
  1105.   echo shar: Will not clobber existing file \"'cxpr/read_header.c'\"
  1106. else
  1107. echo shar: Extracting \"'cxpr/read_header.c'\" \(604 characters\)
  1108. sed "s/^X//" >'cxpr/read_header.c' <<'END_OF_FILE'
  1109. X#include <X11/XWDFile.h>
  1110. X#include <stdio.h>
  1111. X
  1112. XXWDFileHeader    win;
  1113. X
  1114. Xread_header()
  1115. X{
  1116. X    unsigned long    swaptest = 1;
  1117. X
  1118. X    fullread(0, (char *) &win, sizeof(win) );
  1119. X
  1120. X    if (*(char *) &swaptest) _swaplong((char *) &win, (long)sizeof(win));
  1121. X
  1122. X    if (win.file_version != XWD_FILE_VERSION) {
  1123. X    fprintf(stderr,"xpr: file format version missmatch.\n");
  1124. X    return(1);
  1125. X    }
  1126. X
  1127. X    if (win.header_size < sizeof(win)) {
  1128. X    fprintf(stderr,"xpr: header size is too small.\n");
  1129. X    return(1);
  1130. X    }
  1131. X
  1132. X    if (win.byte_order != win.bitmap_bit_order)
  1133. X        fprintf(stderr,"xpr: image will be incorrect, byte swapping error.\n");
  1134. X}
  1135. END_OF_FILE
  1136. if test 604 -ne `wc -c <'cxpr/read_header.c'`; then
  1137.     echo shar: \"'cxpr/read_header.c'\" unpacked with wrong size!
  1138. fi
  1139. # end of 'cxpr/read_header.c'
  1140. fi
  1141. if test -f 'cxpr/read_window_name.c' -a "${1}" != "-c" ; then 
  1142.   echo shar: Will not clobber existing file \"'cxpr/read_window_name.c'\"
  1143. else
  1144. echo shar: Extracting \"'cxpr/read_window_name.c'\" \(251 characters\)
  1145. sed "s/^X//" >'cxpr/read_window_name.c' <<'END_OF_FILE'
  1146. X#include <X11/XWDFile.h>
  1147. X
  1148. Xextern    XWDFileHeader    win;
  1149. Xextern    char        *window_name;
  1150. X
  1151. Xread_window_name()
  1152. X{
  1153. X    window_name = (char *)malloc((unsigned)(win.header_size - sizeof(win)));
  1154. X    fullread(0, window_name, (int) (win.header_size - sizeof(win) ) );
  1155. X}
  1156. END_OF_FILE
  1157. if test 251 -ne `wc -c <'cxpr/read_window_name.c'`; then
  1158.     echo shar: \"'cxpr/read_window_name.c'\" unpacked with wrong size!
  1159. fi
  1160. # end of 'cxpr/read_window_name.c'
  1161. fi
  1162. if test -f 'cxpr/reverse_byte.h' -a "${1}" != "-c" ; then 
  1163.   echo shar: Will not clobber existing file \"'cxpr/reverse_byte.h'\"
  1164. else
  1165. echo shar: Extracting \"'cxpr/reverse_byte.h'\" \(1600 characters\)
  1166. sed "s/^X//" >'cxpr/reverse_byte.h' <<'END_OF_FILE'
  1167. Xchar _reverse_byte[0x100] = {
  1168. X    0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
  1169. X    0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
  1170. X    0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
  1171. X    0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
  1172. X    0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
  1173. X    0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
  1174. X    0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
  1175. X    0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
  1176. X    0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
  1177. X    0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
  1178. X    0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
  1179. X    0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
  1180. X    0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
  1181. X    0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
  1182. X    0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
  1183. X    0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
  1184. X    0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
  1185. X    0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
  1186. X    0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
  1187. X    0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
  1188. X    0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
  1189. X    0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
  1190. X    0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
  1191. X    0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
  1192. X    0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
  1193. X    0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
  1194. X    0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
  1195. X    0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
  1196. X    0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
  1197. X    0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
  1198. X    0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
  1199. X    0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff
  1200. X};
  1201. END_OF_FILE
  1202. if test 1600 -ne `wc -c <'cxpr/reverse_byte.h'`; then
  1203.     echo shar: \"'cxpr/reverse_byte.h'\" unpacked with wrong size!
  1204. fi
  1205. # end of 'cxpr/reverse_byte.h'
  1206. fi
  1207. if test -f 'cxpr/setup_layout.c' -a "${1}" != "-c" ; then 
  1208.   echo shar: Will not clobber existing file \"'cxpr/setup_layout.c'\"
  1209. else
  1210. echo shar: Extracting \"'cxpr/setup_layout.c'\" \(918 characters\)
  1211. sed "s/^X//" >'cxpr/setup_layout.c' <<'END_OF_FILE'
  1212. X#include <stdio.h>
  1213. X#include <X11/XWDFile.h>
  1214. X
  1215. X#define min(x,y) (((x)<(y))?(x):(y))
  1216. X#define F_PORTRAIT      1
  1217. X#define W_MAX 2400
  1218. X#define H_MAX 3150
  1219. X
  1220. Xextern    char        *header, *trailer;
  1221. Xextern    XWDFileHeader    win;
  1222. Xextern    int        scale, width, height, flags;
  1223. X
  1224. Xsetup_layout()
  1225. X{
  1226. X    register    w_scale, w_max, h_scale, h_max;
  1227. X
  1228. X    if (header != NULL)    win.pixmap_height += 75;
  1229. X    if (trailer != NULL)    win.pixmap_height += 75;
  1230. X
  1231. X    /* check maximum width and height; set orientation and scale */
  1232. X
  1233. X    if ( flags & F_PORTRAIT ) {
  1234. X        w_max    = (width  > 0)? width  : W_MAX;
  1235. X        h_max    = (height > 0)? height : H_MAX;
  1236. X        w_scale    = w_max / win.pixmap_width;
  1237. X        h_scale    = h_max / win.pixmap_height;
  1238. X        scale    = min(w_scale, h_scale);
  1239. X    } else {
  1240. X        w_max    = (width  > 0)? width  : H_MAX;
  1241. X        h_max    = (height > 0)? height : W_MAX;
  1242. X        w_scale    = w_max / win.pixmap_width;
  1243. X        h_scale    = h_max / win.pixmap_height;
  1244. X        scale    = min(w_scale, h_scale);
  1245. X    }
  1246. X}
  1247. END_OF_FILE
  1248. if test 918 -ne `wc -c <'cxpr/setup_layout.c'`; then
  1249.     echo shar: \"'cxpr/setup_layout.c'\" unpacked with wrong size!
  1250. fi
  1251. # end of 'cxpr/setup_layout.c'
  1252. fi
  1253. if test -f 'cxpr/swapbits.c' -a "${1}" != "-c" ; then 
  1254.   echo shar: Will not clobber existing file \"'cxpr/swapbits.c'\"
  1255. else
  1256. echo shar: Extracting \"'cxpr/swapbits.c'\" \(196 characters\)
  1257. sed "s/^X//" >'cxpr/swapbits.c' <<'END_OF_FILE'
  1258. X#include "reverse_byte.h"
  1259. X
  1260. X/* copied from lib/X/XPutImage.c */
  1261. X
  1262. X_swapbits (b, n)
  1263. X    register unsigned char *b;
  1264. X    register long n;
  1265. X{
  1266. X    do {
  1267. X        *b = _reverse_byte[*b];
  1268. X        b++;
  1269. X        } while (--n > 0);
  1270. X    
  1271. X}
  1272. END_OF_FILE
  1273. if test 196 -ne `wc -c <'cxpr/swapbits.c'`; then
  1274.     echo shar: \"'cxpr/swapbits.c'\" unpacked with wrong size!
  1275. fi
  1276. # end of 'cxpr/swapbits.c'
  1277. fi
  1278. if test -f 'cxpr/swaplong.c' -a "${1}" != "-c" ; then 
  1279.   echo shar: Will not clobber existing file \"'cxpr/swaplong.c'\"
  1280. else
  1281. echo shar: Extracting \"'cxpr/swaplong.c'\" \(279 characters\)
  1282. sed "s/^X//" >'cxpr/swaplong.c' <<'END_OF_FILE'
  1283. X_swaplong (bp, n)
  1284. X     register char *bp;
  1285. X     register long n;
  1286. X{
  1287. X    register char c;
  1288. X    register char *ep = bp + n;
  1289. X    register char *sp;
  1290. X    do {
  1291. X          sp = bp + 3;
  1292. X        c = *sp;
  1293. X        *sp = *bp;
  1294. X        *bp++ = c;
  1295. X        sp = bp + 1;
  1296. X        c = *sp;
  1297. X        *sp = *bp;
  1298. X        *bp++ = c;
  1299. X        bp += 2;
  1300. X    }
  1301. X    while (bp < ep);
  1302. X}
  1303. END_OF_FILE
  1304. if test 279 -ne `wc -c <'cxpr/swaplong.c'`; then
  1305.     echo shar: \"'cxpr/swaplong.c'\" unpacked with wrong size!
  1306. fi
  1307. # end of 'cxpr/swaplong.c'
  1308. fi
  1309. if test -f 'cxpr/swapshort.c' -a "${1}" != "-c" ; then 
  1310.   echo shar: Will not clobber existing file \"'cxpr/swapshort.c'\"
  1311. else
  1312. echo shar: Extracting \"'cxpr/swapshort.c'\" \(200 characters\)
  1313. sed "s/^X//" >'cxpr/swapshort.c' <<'END_OF_FILE'
  1314. X_swapshort (bp, n)
  1315. X     register char *bp;
  1316. X     register long n;
  1317. X{
  1318. X    register char c;
  1319. X    register char *ep = bp + n;
  1320. X    do {
  1321. X        c = *bp;
  1322. X        *bp = *(bp + 1);
  1323. X        bp++;
  1324. X        *bp = c;
  1325. X        bp++;
  1326. X    }
  1327. X    while (bp < ep);
  1328. X}
  1329. END_OF_FILE
  1330. if test 200 -ne `wc -c <'cxpr/swapshort.c'`; then
  1331.     echo shar: \"'cxpr/swapshort.c'\" unpacked with wrong size!
  1332. fi
  1333. # end of 'cxpr/swapshort.c'
  1334. fi
  1335. echo shar: End of shell archive.
  1336. exit 0
  1337.